package org.gjy.m8.thread;

import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-09-06 14:59:03
 */
public class COWListTest {

    @Test
    public void test1() {
        List<Integer> list = Collections.synchronizedList(Lists.newArrayList(1, 2, 3));
        for (Integer i : list) {
            list.add(i * 2);
        }
        System.out.println(list);
    }

    @Test
    public void test2() {
        CopyOnWriteArrayList<Integer> list = new CopyOnWriteArrayList<>(Lists.newArrayList(1, 2, 3));
        for (Integer i : list) {
            list.add(i * 2);
        }
        System.out.println(list);
    }

}
